<template>
    <h2>科室显示</h2>
    科室名称<input type="text" v-model="KeiShiName">
    科室介绍<input type="text" v-model="KeiShiInfo">
    创建时间<input type="date" v-model="CreateTime">
    <input type="button" value="查询" @click="LoData" style="margin-right: 20px;">
    <input type="button" value="导出" @click="Expor" style="margin-right: 20px;">
    <input type="button" value="导入" @click="Iexport" style="margin-right: 20px;">
    
    




    <table border="1">
        <thead>
        <tr>
            <td>科室编号</td>
            <td>科室名称</td>
            <td>科室人数</td>
            <td>科室介绍</td>
            <td>添加科室操作人</td>
            <td>添加科室操作时间</td>
            <td>操作列</td>
        
        </tr>
    </thead>
    <tbody>
        <tr v-for="item in info">
            <td>{{item.KeiShiId}}</td>
            <td>{{item.KeiShiName}}</td>
            <td>{{item.KeiShiNum}}</td>
            <td>{{item.KeiShiInfo}}</td>
            <td>{{item.D_AddUser}}</td>
            <td>{{item.CreateTime.substring(0,10)}}</td>
            <td>操作列
                <a @click="Del(item.KeiShiId)" style="margin-right: 20px;">删除</a>
                <a @click="Upd(item.KeiShiId)" style="margin-right: 20px;">修改</a>
            </td>
        
        </tr>
    </tbody>
    </table>
</template>
<script setup lang="ts">
import axios from "axios";
import { onMounted,ref } from "vue";
import { useRouter,useRoute } from "vue-router";


const router=useRouter();

//修改
const Upd=(Kid:number)=>{
    router.push({
        name:"UpdateKeiShi",
        params:{
            id:Kid

        }
    })
}


//导入
const Iexport=()=>{
axios.get('https://localhost:7133/api/KeiShi/Ixport?Fpath='+'D:\\Users\\27084\\王梦真11.29月考题\\KeiShiIns.xlsx')
.then(res=>{
    if(res.data>0){
        alert("导入成功");
    }
    else{
        alert("导入失败");
    }
})
}

//导出
const Expor=()=>{
    axios.post('https://localhost:7133/api/KeiShi/Export?Fpath='+'D:\\Users\\27084\\王梦真11.29月考题\\KeiShiIns.xlsx')
    .then(res=>{
        if(res.data>0){
            alert("导出成功");
        }
        else{
            alert("导出失败");
        }
    })
}

//删除
const Del=(Kid:number)=>{
    if(confirm("你确定要删除吗?")){
        axios.get('https://localhost:7133/api/KeiShi/DelKeiShi',
        {
            params:{
                KeiShiId:Kid
            }
        }
        )
        .then(res=>{
            if(res.data>0){
                alert("删除成功");
                LoData();
            }
            else{
                alert("删除失败");
            }
        })
    }
}

const KeiShiName=ref("");
const KeiShiInfo=ref("");
const CreateTime=ref("");

const info=ref([{

    KeiShiName:"",
    KeiShiInfo:"",
    KeiShiId:0,
    KeiShiNum:"",
    CreateTime:"",
    D_AddUser:""

    
}])

//加载数据
onMounted(()=>{
    LoData();
})

const LoData=()=>{
    axios.get('https://localhost:7133/api/KeiShi/ShowKeiShi',
    {
        params:{
            KeiShiName:KeiShiName.value,
            KeiShiInfo:KeiShiInfo.value,
            CreateTime:CreateTime.value
        }
    }
    
    )

    .then(res=>{
        info.value=res.data
    })

}




</script>